package com.znxz.hzqiuxm.ziniublog.user.domain.services;

import com.znxz.hzqiuxm.ziniublog.global.common.SysConst;
import com.znxz.hzqiuxm.ziniublog.user.domain.dao.UserRepository;
import com.znxz.hzqiuxm.ziniublog.user.domain.entity.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * 用户相关服务类
 * @Date 2018/8/30 20:47
 */
@Service
public class UserServices {

    @Autowired
    private UserRepository userRepository;

    /**
     * 查询所有的用户信息
     * @return
     */
    public List<UserDO> getUser(){

        return userRepository.findAll();
    }

    /**
     * 添加一名用户
     * @param userDO
     * @return
     */
    public UserDO addUser(UserDO userDO){

        //注册时间
        userDO.setGmtCreate(LocalDateTime.now());
        //默认角色
        List<String> rolelist = new ArrayList<>();
        rolelist.add(SysConst.ROLE_USER);
        userDO.setRoles(rolelist);

        return userRepository.save(userDO);
    }

}
